package com.mes.task.dao;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Property;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.bstek.dorado.data.provider.Page;
import com.mes.common.dao.BasicDao;
import com.mes.task.dao.iface.IDemandChangeDao;
import com.mes.task.domain.DemandChange;

@Repository
public class DemandChangeDao extends BasicDao<DemandChange> implements IDemandChangeDao {

	private static final Log log = LogFactory.getLog(DemandChangeDao.class);

	@Override
	public List<DemandChange> getChangesByDemandUid(String demandUid, Page<DemandChange> page) {
		List<DemandChange> list = null;
		try {
			DetachedCriteria crit = DetachedCriteria.forClass(DemandChange.class);
			crit.add(Restrictions.like("demandUid", demandUid));
			crit.addOrder(Property.forName("createTime").desc());

			// 如果需要进行分页处理，则调用如下语句
			if (page != null) {
				this.pagingQuery(page, crit);
			} else {
				list = this.query(crit, null);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}

}
